/**
 * @project readnote
 * @Title BookDAOImpl.java
 * @author huxh
 * @date 2012-2-12
 **/
package com.readnote.book.dao.impl;

import java.util.List;

import com.cr.backbone.hibenate.AppBaseDAOImpl;
import com.readnote.book.dao.UserBookDAO;
import com.readnote.book.model.Book;
import com.readnote.book.model.UserBook;
import com.readnote.user.model.User;

public class UserBookDAOImpl extends AppBaseDAOImpl<UserBook> implements  UserBookDAO {

	/**
	 * 获取单个用户书籍对象,by用户、书籍
	 * @param book
	 * @param user
	 * @return
	 */
	public UserBook getUserBookByBookAndUser(Book book, User user) {
		String hql="FROM UserBook ub where ub.user.id = ? and ub.book.id = ?";
//		String[] paramNames={"userId","bookId"};
		Object[] values={user.getId(),book.getId()};
		return getByHql(hql, values);
	}
	
	
	
	/**
	 * 获取用户书籍集合，by用户
	 * @param user
	 * @return
	 */
	public List<UserBook> getListUserBookByUser(User user) {
		String hql="FROM UserBook ub where ub.user.id = :userId";
		String[] paramNames={"userId"};
		Object[] values={user.getId()};
		return getListByHql(hql, paramNames, values);
	}
	
	
}
